<?php

namespace app\admin\controller;

use think\Controller;
use think\Request;
use app\admin\model\Cardtype;
use app\admin\model\Luntan;
use think\Paginator;
class Type extends Controller
{
    /**
     * 显示资源列表
     *
     * @return \think\Response
     */
    public function index()
    {
        $data=Cardtype::select();
        return $this->fetch('type',['data'=>$data]);
    }
    public function do_type(Request $request){
          $type=new Cardtype();
        $type->cardtype=$request->param('cardtype');
        if($type->save()){
            $this->success('添加类型成功','/admin/type/typelist');
        }else{
            $this->error('添加失败');
        }
    }
    public function typelist(){

        return $this->fetch('typelist');

    }
    public function do_typelist(Request $request){
        $list=Cardtype::paginate(5)->toArray();


        return json(['data'=>$list]);
    }
    public function typedel(Request $request){
        $ids=$request->param('ids');
        $data=Cardtype::get($ids);
        $data->dstaust=0;
        $data->save();
        return json(['code'=>200,'data'=>'删除成功']);
    }

    public function typeupd(Request $request){
        $id=$request->param('id');
        // print_r($id);die;
        $data=Cardtype::get($id);

        return $this->fetch('typeupd',['user'=>$data]);

    }

    public function do_typeupd(Request $request){
        $id=$request->param('id');
        $typeupd=Cardtype::get($id);
        $typeupd->cardtype=$request->param('cardtype');

        if($typeupd->save()){
            $this->success('修改成功','/admin/type/typelist');
        }
        else{
            $this->error('修改失败');
        }

    }



}
